namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using SimpleWebServices;
    using SimpleWebServices.Globalization;
    using Xunit;

    public sealed class TextStringFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<TextString>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IElement>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new TextString());
        }

        [Fact]
        public void ctor_string()
        {
            Assert.NotNull(new TextString("value"));
        }

        [Fact]
        public void ctor_stringEmpty()
        {
            Assert.NotNull(new TextString(string.Empty));
        }

        [Fact]
        public void ctor_stringNull()
        {
            Assert.NotNull(new TextString(null as string));
        }

        [Fact]
        public void prop_Value()
        {
            Assert.True(new PropertyExpectations(typeof(TextString).GetProperty("Value"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Id_get()
        {
            Assert.Null((new TextString() as IElement).Id);
        }

        [Fact]
        public void prop_Id_set()
        {
            Assert.Throws<NotSupportedException>(() => (new TextString() as IElement).Id = new Name("token"));
        }

        [Fact]
        public void prop_Class_get()
        {
            Assert.Null((new TextString() as IElement).Class);
        }

        [Fact]
        public void prop_Class_set()
        {
            Assert.Throws<NotSupportedException>(() => (new TextString() as IElement).Class = new Names());
        }

        [Fact]
        public void prop_Language_get()
        {
            Assert.Null((new TextString() as IElement).Language);
        }

        [Fact]
        public void prop_Language_set()
        {
            Assert.Throws<NotSupportedException>(() => (new TextString() as IElement).Language = new Language());
        }

        [Fact]
        public void prop_Title_get()
        {
            Assert.Null((new TextString() as IElement).Title);
        }

        [Fact]
        public void prop_Title_set()
        {
            Assert.Throws<NotSupportedException>(() => (new TextString() as IElement).Title = string.Empty);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            IElementSerializable obj = (new TextString() as IElementSerializable).Deserialize("text", null, "<text>value</text>");

            Assert.Null(obj);
        }

        [Fact]
        public void op_Render()
        {
            string expected = "value";
            string actual = (new TextString(expected) as IElementSerializable).Render();

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_Render_whenIllegalCharacters()
        {
            string expected = "&amp;&lt;&gt;";
            string actual = (new TextString("&<>") as IElementSerializable).Render();

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToElement()
        {
            IElement expected = new TextString();
            IElement actual = (expected as IElementSerializable).ToElement();

            Assert.Same(expected, actual);
        }

        [Fact]
        public void op_ToString()
        {
            string expected = "value";
            string actual = new TextString(expected).ToString();

            Assert.Equal<string>(expected, actual);
        }
    }
}